package com.ruoyi.system.service;

import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CommonUtilUrlService {

    /*@Value("{server.key}")
    private String key;

    @Value("{server.imgurl}")
    private String imgurl;*/

    public String post(String url,String json) throws Exception{
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, json);
        Request request = new Request.Builder()
                .url(url).method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();
        String dataJson = response.body().string();
        JSONObject jsonData = JSONObject.parseObject(dataJson);
        return jsonData.getString("msg");
    }
}
